package com.bana.fvs.app.main.view;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bana.fvs.R;

/**
 * Author : yanftch
 * Date : 2018/2/14
 * Time : 17:04
 * Desc : 通用的顶部的刷新视图
 */

public class CommonHeadRefreshView {
    private Context mContext;
    private View rootView;
    private TextView mTimeView;//时间
    private ImageView mRefreshView;//刷新
    private ITimeRefresh mITimeRefresh;

    public void setITimeRefresh(ITimeRefresh iTimeRefresh) {
        this.mITimeRefresh = iTimeRefresh;
    }

    public interface ITimeRefresh {
        void onRefresh();
    }


    public CommonHeadRefreshView(Context context, View rootView, String time) {
        mContext = context;
        this.rootView = rootView;
        initView(time);
        initListener();
    }

    public void refreshData(String time) {
        mTimeView.setText(mContext.getString(R.string.refreshTime) + time);
    }

    //初始化
    private void initView(String time) {
        mTimeView = rootView.findViewById(R.id.commonHeadRefreshTimeView);
        mRefreshView = rootView.findViewById(R.id.commonHeadRefreshButton);
        mTimeView.setText(mContext.getString(R.string.refreshTime) + time);
    }

    private void initListener() {
        mRefreshView.setOnClickListener(v -> {
            if (null != mITimeRefresh) {
                mITimeRefresh.onRefresh();
            }
        });
    }
}
